package com.czxy.tanhua.controller;

import com.czxy.tanhua.interceptor.UserHolder;
import com.czxy.tanhua.service.CommentService;
import com.czxy.tanhua.vo.CommentTdo;
import com.czxy.tanhua.vo.PublicPageVo;
import com.czxy.tanhua.vo.ResultList;
import org.bson.types.ObjectId;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;

/**
 * @Author 爱吃豆的土豆、
 * @Date 2023/4/12 21:43
 */
@RestController
@RequestMapping("/comments")
public class CommentController {
    @Resource
    private CommentService commentService;
    @GetMapping
    public ResponseEntity findComments(@RequestParam("movementId") ObjectId movementId, PublicPageVo publicPageVo){
        System.out.println(movementId);
        ResultList comments = commentService.findComments(movementId, publicPageVo);
        return ResponseEntity.ok(comments);
    }
    @PostMapping
    public ResponseEntity addcomment(@RequestBody CommentTdo commentTdo){
        System.out.println(commentTdo);
        commentService.addcomment(commentTdo, UserHolder.getUserId());
        return ResponseEntity.ok(null);
    }
}
